package io.gitee.hefren.hhcache.core;

import com.google.common.base.MoreObjects;

/**
 * @Date 2024/7/9
 * @Author lifei
 */
public class Reply<T> {

    private T value;
    private ReplyTypeEnum replyTypeEnum;

    public Reply() {
    }

    public Reply(T value, ReplyTypeEnum replyTypeEnum) {
        this.value = value;
        this.replyTypeEnum = replyTypeEnum;
    }

    public static Reply<?> simpleStringReply(String value) {
        return new Reply<>(value, ReplyTypeEnum.SIMPLY_STRING);
    }

    public static Reply<?> bulkStringReply(String value) {
        return new Reply<>(value, ReplyTypeEnum.BULK_STRING);
    }

    public static Reply<?> integerReply(Integer value) {
        return new Reply<>(value, ReplyTypeEnum.INTEGER);
    }

    public static Reply<?> errorReply(String value) {
        return new Reply<>(value, ReplyTypeEnum.ERROR);
    }

    public static Reply<?> arrayReply(String[] value) {
        return new Reply<>(value, ReplyTypeEnum.ARRAY);
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public ReplyTypeEnum getReplyTypeEnum() {
        return replyTypeEnum;
    }

    public void setReplyTypeEnum(ReplyTypeEnum replyTypeEnum) {
        this.replyTypeEnum = replyTypeEnum;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(Reply.class)
                .add("value", value)
                .add("replyTypeEnum", replyTypeEnum)
                .toString();
    }
}
